import { getCookie, setCookie } from "@/utils/cookie";
import { createSlice } from "@reduxjs/toolkit";

export const MenuPath = createSlice({
  name: 'menuPath',
  initialState: {
    value: getCookie('path') || 'users', // menu当前项
    openKey: getCookie('keys') || 'sub1' // 当前展开的 SubMenu 菜单项 key 数组
  },
  reducers: {
    savePath: (state, action) => {
      setCookie('path', action.payload)
      state.value = action.payload
    },

    saveKeys: (state, action) => {
      setCookie('keys', action.payload)
      state.value = action.payload
    }
  }
}) 

export const { savePath, saveKeys } = MenuPath.actions
export default MenuPath.reducer